#!/usr/bin/python
# GM_alterpars.py
'''A suite of little functions to swap between versions of variables.'''

import numpy


VariableNames = ['ScaleList', 'vanillaScaleList', 'modifiedScaleList', 'MvList', 'vanillaMvList', 'modifiedMvList', 'LumFuncList', 'vanillaLumFuncList', 'modifiedLumFuncList', 'delMvList', 'vanilladelMvList', 'modifieddelMvList', 'MvVals', 'vanillaMvVals', 'modifiedMvVals', 'limitset', 'vanillalimitset', 'modifiedlimitset', 'delMvVals', 'vanilladelMvVals', 'modifieddelMvVals', 'MvMass', 'vanillaMvMass', 'modifiedMvMass', 'delMvMass', 'vanilladelMvMass', 'modifieddelMvMass', 'limitsMvMass', 'vanillalimitsMvMass', 'modifiedlimitsMvMass', 'MvMassScales', 'vanillaMvMassScales', 'modifiedMvMassScales']


def swap_mags(phypars, vanilla=True):
    '''Switch between descriptions of the luminosity function.

    Affected variables are ScaleList, MvList, LumFuncList, delMvList, MvVals, limitset, delMvVals.'''
    for i in phypars:
        cmd = "%s = phypars['%s']" % (i,i)
        exec cmd
    if vanilla == True:
        ScaleList = numpy.array(vanillaScaleList)
        MvList = numpy.array(vanillaMvList)
        LumFuncList = numpy.array(vanillaLumFuncList)
        delMvList = numpy.array(vanilladelMvList)
        MvVals = numpy.array(vanillaMvVals)
        limitset = numpy.array(vanillalimitset)
        delMvVals = numpy.array(vanilladelMvVals)
#         = numpy.array(vanilla)
    elif vanilla == False:
        ScaleList = numpy.array(modifiedScaleList)
        MvList = numpy.array(modifiedMvList)
        LumFuncList = numpy.array(modifiedLumFuncList)
        delMvList = numpy.array(modifieddelMvList)
        MvVals = numpy.array(modifiedMvVals)
        limitset = numpy.array(modifiedlimitset)
        delMvVals = numpy.array(modifieddelMvVals)
#         = numpy.array(modified)
    else:
        print "The second, optional input parameter to GM_Swap.swap_absmags must be boolean.  Your results may be funny."
    for i in phypars:
        cmd = "phypars['%s'] = %s" % (i,i)
        exec cmd
    return phypars


def swap_mass(phypars, vanilla=True):
    '''Switch between descriptions of the mass-luminosity relation.

    Affected variables are MvMass, delMvMass, limitsMvMass, MvMassScales.'''
    for i in phypars:
        cmd = "%s = phypars['%s']" % (i,i)
        exec cmd
    if vanilla == True:
        MvMass = numpy.array(vanillaMvMass)
        delMvMass = numpy.array(vanilladelMvMass)
        limitsMvMass = numpy.array(vanillalimitsMvMass)
        MvMassScales = numpy.array(vanillaMvMassScales)
#         = numpy.array(vanilla)
    elif vanilla == False:
        MvMass = numpy.array(modifiedMvMass)
        delMvMass = numpy.array(modifieddelMvMass)
        limitsMvMass = numpy.array(modifiedlimitsMvMass)
        MvMassScales = numpy.array(modifiedMvMassScales)
#         = numpy.array(modified)
    else:
        print "The second, optional input parameter to GM_Swap.swap_mass must be boolean.  Your results may be funny."
    for i in phypars:
        cmd = "phypars['%s'] = %s" % (i,i)
        exec cmd
    return phypars


def swap_all(phypars, vanilla=True):
    '''Execute swap_mags and swap_mass in one function call.'''
    for i in phypars:
        cmd = "%s = phypars['%s']" % (i,i)
        exec cmd
    if vanilla == True:
        swap_mags(phypars, True)
        swap_mass(phypars, True)
#         = numpy.array(vanilla)
    elif vanilla == False:
        swap_mags(phypars, False)
        swap_mass(phypars, False)
#         = numpy.array(modified)
    else:
        print "The second, optional input parameter to GM_Swap.swap_all must be boolean.  Your results may be funny."
    for i in phypars:
        cmd = "phypars['%s'] = %s" % (i,i)
        exec cmd
    return phypars


def swap_fitting(phypars, vanilla=True):
    '''Used specifically to swap in a useful array for fitting purposes.

    Affected variables are MvVals, limitset, delMvVals (a subset of those swapped in swap_mags).'''
    for i in phypars:
        cmd = "%s = phypars['%s']" % (i,i)
        exec cmd
    if vanilla == True:
        MvVals = numpy.array(vanillaMvVals)
        limitset = numpy.array(vanillalimitset)
        delMvVals = numpy.array(vanilladelMvVals)
#         = numpy.array(vanilla)
    elif vanilla == False:
        MvVals = numpy.array(fittingMvVals)
        limitset = numpy.array(fittinglimitset)
        delMvVals = numpy.array(fittingdelMvVals)
#         = numpy.array(fitting)
    else:
        print "The second, optional input parameter to GM_Swap.swap_fitting must be boolean.  Your results may be funny."
    for i in phypars:
        cmd = "phypars['%s'] = %s" % (i,i)
        exec cmd
    return phypars
